package com;

import com.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.Reader;

public class UserTest {
    @Test
    public void userFindByIdTest(){
       String resources = "mybatis-config.xml";
       Reader reader = null;
       try {
           reader = Resources.getResourceAsReader(resources);
       }catch (Exception e){
           e.printStackTrace();
       }
       SqlSessionFactory sqlMapper = new SqlSessionFactoryBuilder().build(reader);
       SqlSession sqlSession = sqlMapper.openSession();
        User user = sqlSession.selectOne("findUserById", 1);
        System.out.println(user.getUname());
        sqlSession.close();
    }
}
